# class for hanja

import csv

NAME_LIST = ['hanja', 'pronan', 'meaning', 'stroke', 'five_element']


class PronanDict(dict):
  def add(self, key, item):
    if self.get(key):
      assert type(self[key]) == list
      self[key].append(item)
    else:
      self[key] = [item]

class HanjaDict:
  def __init__(self, filename):
    """
    filename: csv file
      hanja, pronan, meaning, stroke, five_element
    """
    reader = csv.DictReader(open(filename), NAME_LIST)
    self._hanja_list = []
    self._pronan_dict = PronanDict({})
    for row in reader:
      self._hanja_list.append(row)
      self._pronan_dict.add(row['pronan'], row)

  def GetHanjaItem(self, pronan):
    return self._pronan_dict.get(pronan)
